home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / netpq.zip / MENUDRVR.C < prev    next >
Text File  |  1992-02-24  |  3KB  |  132 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. #include "nos.h"
  5. #include "noslib.h"
  6. #include "netpq.h"
  7.  
  8. int selection, xbase, ybase;
  9.  
  10.  
  11. menu (char *prompts [], int numberofprompts, int xsize, int x, int y)
  12. {
  13. //  displays the prompts in *prompts as a menu and allows the operator
  14. //  to select one of the prompts through use of the cursor keys.
  15.  
  16. int i;
  17.  
  18.     xbase = x;
  19.     ybase = y;
  20.     selection = 0;
  21.  
  22.     gotoxy (xbase, (ybase++) );
  23.     nohighlight ();
  24.     cprintf (" ╔");
  25.     for (i = 1; i <= xsize; i++)
  26.         cprintf ("═");
  27.     cprintf ("╗ ");
  28.  
  29.     while (selection < numberofprompts)
  30.         {
  31.         displayoneprompt (prompts, xsize, false);
  32.         selection++;
  33.         }
  34.  
  35.     gotoxy (xbase, (ybase + selection) );
  36.     cprintf (" ╚");
  37.     for (i = 1; i <= xsize; i++)
  38.         cprintf ("═");
  39.     cprintf ("╝ ");
  40.  
  41.     getchoice (prompts, xsize, numberofprompts);
  42.  
  43.     return selection;
  44. }
  45.  
  46.  
  47.  
  48. getchoice (char *prompts [], int xsize, int numberofprompts)
  49. {
  50. //  handles operator actions
  51.  
  52.     selection = 0;
  53.  
  54.     while (true)
  55.         {
  56.         displayoneprompt (prompts, xsize, true);
  57.  
  58.         while (kbhit () == 0);
  59.  
  60.         switch (getextch ())
  61.             {
  62.             case key_home:
  63.                 displayoneprompt (prompts, xsize, false);
  64.                 selection = 0;
  65.                 break;
  66.  
  67.             case key_end:
  68.                 displayoneprompt (prompts, xsize, false);
  69.                 selection = numberofprompts - 1;
  70.                 break;
  71.  
  72.             case key_cursorup:
  73.                 displayoneprompt (prompts, xsize, false);
  74.                 do
  75.                     {
  76.                     selection--;
  77.                     if (selection < 0)
  78.                         selection = numberofprompts - 1;
  79.                     }
  80.                     while (strlen (prompts [selection]) == 0);
  81.                 break;
  82.  
  83.             case key_cursordown:
  84.                 displayoneprompt (prompts, xsize, false);
  85.                 do
  86.                     {
  87.                     selection++;
  88.                     if (selection >= numberofprompts)
  89.                         selection = 0;
  90.                     }
  91.                     while (strlen (prompts [selection]) == 0);
  92.                 break;
  93.  
  94.             case key_esc:
  95.             case key_cursorleft:
  96.                 displayoneprompt (prompts, xsize, false);
  97.                 selection = -1;
  98.  
  99.             case key_enter:
  100.             case key_cursorright:
  101.                 return (selection);
  102.  
  103.             default:
  104.                 printf ("\a");
  105.             }
  106.         }
  107. }
  108.  
  109.  
  110.  
  111.  
  112. displayoneprompt (char *prompts [], int xsize, int flag)
  113. {
  114. //  displays one prompt string
  115.  
  116.     gotoxy (xbase, (ybase + selection) );
  117.  
  118.     cprintf (" ║");
  119.  
  120.     if (flag == true)
  121.         highlight ();
  122.     else
  123.         nohighlight ();
  124.  
  125.     cprintf ("%-*s", xsize, prompts [selection]);
  126.  
  127.     nohighlight ();
  128.     cprintf ("║ ");
  129.  
  130.     gotoxy ( (xbase + 2), (ybase + selection) );
  131. }
  132.